<template>
  <div class="article-page">
    <div class="banner">
      <div class="container">
        <h1>{{article.title}}</h1>
        <article-meta :article='article'/>
      </div>
    </div>
    <div class="container page">
      <div class="row article-content">
        <!-- 文章正文 -->
        <div class="col-md-12" v-html="article.body"></div>
      </div>
      <hr />
      <div class="article-actions">
        <article-meta :article='article'/>
      </div>
      <!-- 文章评论列表 -->
      <div class="row">
        <atticle-comments :article='article'/>
      </div>
    </div>
  </div>
</template>
<script>
import { getArticle } from '@/api/article'
import MarkdownIt from 'markdown-it'
import articleMeta from './components/articleMeta'
import atticleComments from './components/articleComments'
export default {
  data(){
    return{}
  },
  components:{
    articleMeta, // 用户相关组件
    atticleComments // 评论组件
  },
 async asyncData({params}){
    // 获取文章详情数据
    const { article } = await getArticle(params.slug)
    // 解析文章正文内容的markDowm语法
    const md = new MarkdownIt()
    article.body = md.render(article.body)
    return { article }
  },
  // 设置头部信息有利于SEC
  head () {
    return {
      title: `${this.article.title} - RealWorld`,
      meta: [
        { hid: 'description', name: 'description', content: this.article.description }
      ]
    }
  }
}
</script>